<?php
namespace Home\Controller;

use Common\Controller\UserBaseController;

/**
 * 首页控制器
 */
class DayresultController extends UserBaseController
{

    /**
     *  获取当天所有期数开奖结果
     */
    public function index()
    {
        $c_type = $_GET['lottery'];
        $g_time = $_GET['_'];
        $data   = array();
        $day    = date();
        header('Content-type:application/json,charset=UTF-8');
        switch ($c_type) {
            //幸运飞艇
            case 'XYFT': //幸运飞艇 彩种id 5

                //$start_time=strtotime($day.' '.$open_time[1]['kp_time']);
                //$end_time=strtotime($day.' '.$open_time[180]['kj_time'])+3*60;
                //print_r($open_time);exit;
                $condition['c_id'] = 5;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                foreach ($result as $k => $v) {
                    $detail = explode(',', $v['lottery_result']);
                    $lm     = explode(',', $v['lm']);
                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value > 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['GDX'][0]        = $lm[2];
                        $detail['GDS'][0]        = $lm[1];
                        $detail['GYH'][0]        = $lm[0];
                    }

                    $data[$k]['detail'] = $detail;

                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //北京PK10
            case 'BJPK10': //北京PK10 彩种id 4

                $condition['c_id'] = 4;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();

                foreach ($result as $k => $v) {
                    $detail = explode(',', $v['lottery_result']);
                    $lm     = explode(',', $v['lm']);
                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value > 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['GDX'][0]        = $lm[2];
                        $detail['GDS'][0]        = $lm[1];
                        $detail['GYH'][0]        = $lm[0];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //重庆时时彩
            case 'CQSSC': //重庆时时彩 彩种id 1

                $start_time            = strtotime(date('Y-m-d', time()));
                $condition['c_id']     = 1;
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->limit(40)->order('c_no desc')->select();
                foreach ($result as $k => $v) {

                    $detail = explode(',', $v['lottery_result']);

                    $lm = explode(',', $v['lm']);
                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;

            //新疆时时彩
            case 'XJSSC': //新疆时时彩 彩种id 2

                $condition['c_id'] = 2;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                foreach ($result as $k => $v) {
                    $detail = explode(',', $v['lottery_result']);
                    $lm     = explode(',', $v['lm']);

                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //天津时时彩
            case 'TJSSC': //天津时时彩 彩种id 3

                $condition['c_id'] = 3;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                foreach ($result as $k => $v) {
                    $detail = explode(',', $v['lottery_result']);
                    $lm     = explode(',', $v['lm']);
                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //重庆幸运农场
            case 'XYNC': //重庆幸运农场 彩种id 8

                $condition['c_id']     = 8;
                $start_time            = strtotime(date('Y-m-d'), time());
                $condition['add_time'] = array('gt', $start_time);

                $result = M('lottery_results')->where($condition)->order('add_time desc')->select();
                $detail = array();
                foreach ($result as $k => $v) {
                    $num = explode(',', $v['lottery_result']);
                    $lm  = explode(',', $v['lm']);
                    foreach ($num as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 20;
                        if ($value >= 11) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        $wdx = $value % 10;
                        if ($wdx >= 5) {
                            $wdx = '大';
                        } else {
                            $wdx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $he = $value % 10 + $value / 10 % 10;
                        if ($he % 2 == 1) {
                            $hds = '单';
                        } else {
                            $hds = '双';
                        }
                        if ($value <= 7) {
                            $zfb = '中';
                        } elseif ($value <= 14 && $value > 7) {
                            $zfb = '发';
                        } else {
                            $zfb = '白';
                        }
                        if (in_array($value, array(1, 5, 9, 13, 17))) {
                            $fw = '东';
                        } elseif (in_array($value, array(2, 6, 10, 14, 18))) {
                            $fw = '南';
                        } elseif (in_array($value, array(3, 7, 11, 15, 19))) {
                            $fw = '西';
                        } else {
                            $fw = '北';
                        }

                        $detail['DX' . $key2][0]  = $dx;
                        $detail['WDX' . $key2][0] = $wdx;
                        $detail['DS' . $key2][0]  = $ds;
                        $detail['HDS' . $key2][0] = $hds;
                        $detail['LH' . $key2][0]  = $this->lh($num, $key2);
                        $detail['ZFB' . $key2][0] = $zfb;
                        $detail['FW' . $key2][0]  = $fw;

                        $detail['ZDX'][0]  = $lm[2];
                        $detail['ZDS'][0]  = $lm[1];
                        $detail['ZWDX'][0] = $lm[3];

                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //广东快乐十分
            case 'GDKLSF': //广东快乐十分 彩种id 6

                $condition['c_id']     = 6;
                $start_time            = strtotime(date('Y-m-d'), time());
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                $detail                = array();
                foreach ($result as $k => $v) {
                    $num = explode(',', $v['lottery_result']);
                    $lm  = explode(',', $v['lm']);
                    foreach ($num as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 20;
                        if ($value >= 11) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $he = $value % 10 + $value / 10 % 10;
                        if ($he % 2 == 1) {
                            $hds = '单';
                        } else {
                            $hds = '双';
                        }
                        $detail['DX' . $key2][0]  = $dx;
                        $detail['DS' . $key2][0]  = $ds;
                        $detail['HDS' . $key2][0] = $hds;
                        $detail['LH' . $key2][0]  = $this->lh($num, $key2);

                        $detail['ZDX'][0]  = $lm[2];
                        $detail['ZDS'][0]  = $lm[1];
                        $detail['ZWDX'][0] = $lm[3];

                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //广西快三
            case 'GXK3': //广西快三 彩种id 7

                $condition['c_id']     = 7;
                $start_time            = strtotime(date('Y-m-d'), time());
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //PC蛋蛋
            case 'PCEGG': //PC蛋蛋 彩种id 11

                $condition['c_id']     = 11;
                $start_time            = strtotime(date('Y-m-d'), time());
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //北京快8
            case 'BJKL8': //北京快8 彩种id 9

                $condition['c_id']     = 9;
                $start_time            = strtotime(date('Y-m-d'), time());
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc ')->select();
                $detail                = array();
                foreach ($result as $k => $v) {
                    $num = explode(',', $v['lottery_result']);
                    $sum = array_sum($num);

                    foreach ($num as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($sum > 810) {
                            $dx = '大';
                        } elseif ($sum < 810) {
                            $dx = '小';
                        } else {
                            $dx = '和';
                        }
                        if ($sum % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }

                        $detail['ZHT'][0] = $sum;
                        $detail['ZDX'][0] = $dx;
                        $detail['ZDS'][0] = $ds;
                        $detail['QHH'][0] = $this->zh_qh($num);
                        $detail['DSH'][0] = $this->zh_dsh($num);
                        $detail['WX'][0]  = $this->wx($sum);
                    }

                    $data[$k]['detail'] = $detail;

                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //广西快乐十分
            case 'GXKLSF': //广西快乐十分 彩种id 10

                $condition['c_id']     = 10;
                $start_time            = strtotime(date('Y-m-d'), time());
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();

                $detail = array();
                foreach ($result as $k => $v) {
                    $num = explode(',', $v['lottery_result']);
                    $lm  = explode(',', $v['lm']);
                    foreach ($num as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 20;
                        if ($value >= 11) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        $wdx = $value % 10;
                        if ($wdx >= 5) {
                            $wdx = '大';
                        } else {
                            $wdx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $he = $value % 10 + $value / 10 % 10;
                        if ($he % 2 == 1) {
                            $hds = '单';
                        } else {
                            $hds = '双';
                        }
                        $detail['YDX' . $key2][0]   = $dx;
                        $detail['YWDX' . $key2][0]  = $wdx;
                        $detail['YDS' . $key2][0]   = $ds;
                        $detail['YHDS' . $key2][0]  = $hds;
                        $detail['SB' . $key2][0]    = $this->color($value);
                        $detail['YFLSX' . $key2][0] = $this->fulsx($value);
                        $detail['LH15'][0]          = $lm[3];

                        $detail['ZDX'][0] = $lm[2];
                        $detail['ZDS'][0] = $lm[1];

                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //分分彩
            case 'FFC': //分分彩 彩种id 13

                $condition['c_id'] = 13;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                foreach ($result as $k => $v) {
                    $detail = explode(',', $v['lottery_result']);
                    $lm     = explode(',', $v['lm']);

                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //QQ分分彩
            case 'QQFFC': //分分彩 彩种id 16

                $condition['c_id'] = 16;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                foreach ($result as $k => $v) {
                    $detail = explode(',', $v['lottery_result']);
                    $lm     = explode(',', $v['lm']);

                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //腾讯分分彩
            case 'TXFFC': //腾讯分分彩 彩种id 17

                $condition['c_id'] = 17;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                foreach ($result as $k => $v) {
                    $detail = explode(',', $v['lottery_result']);
                    $lm     = explode(',', $v['lm']);

                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //加拿大快乐8
            case 'JNDKL8': //加拿大快乐8 彩种id 15

                $condition['c_id'] = 15;
                $start_time        = strtotime(date('Y-m-d', time()));

                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc')->select();
                $detail                = array();
                foreach ($result as $k => $v) {
                    $num = explode(',', $v['lottery_result']);
                    $sum = array_sum($num);

                    foreach ($num as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($sum > 810) {
                            $dx = '大';
                        } elseif ($sum < 810) {
                            $dx = '小';
                        } else {
                            $dx = '和';
                        }
                        if ($sum % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }

                        $detail['ZHT'][0] = $sum;
                        $detail['ZDX'][0] = $dx;
                        $detail['ZDS'][0] = $ds;
                        $detail['QHH'][0] = $this->zh_qh($num);
                        $detail['DSH'][0] = $this->zh_dsh($num);
                        $detail['WX'][0]  = $this->wx($sum);
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //加拿大3.5
            case 'JND': //加拿大3.5 彩种id 24

                $start_time            = strtotime(date('Y-m-d', time()));
                $condition['c_id']     = 24;
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->limit(40)->order('c_no desc')->select();
                foreach ($result as $k => $v) {

                    $detail = explode(',', $v['lottery_result']);

                    $lm = explode(',', $v['lm']);
                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //台湾宾果
            case 'TWBG': //台湾宾果 彩种id 22

                $condition['c_id']     = 22;
                $start_time            = strtotime(date('Y-m-d'), time());
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->order('add_time desc ')->select();
                $detail                = array();
                foreach ($result as $k => $v) {
                    $num = explode(',', $v['lottery_result']);
                    $sum = array_sum($num);

                    foreach ($num as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($sum > 810) {
                            $dx = '大';
                        } elseif ($sum < 810) {
                            $dx = '小';
                        } else {
                            $dx = '和';
                        }
                        if ($sum % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }

                        $detail['ZHT'][0] = $sum;
                        $detail['ZDX'][0] = $dx;
                        $detail['ZDS'][0] = $ds;
                        $detail['QHH'][0] = $this->zh_qh($num);
                        $detail['DSH'][0] = $this->zh_dsh($num);
                        $detail['WX'][0]  = $this->wx($sum);
                    }

                    $data[$k]['detail'] = $detail;

                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;
            //台湾五分
            case 'TWWF': //台湾五分 彩种id 23

                $start_time            = strtotime(date('Y-m-d', time()));
                $condition['c_id']     = 23;
                $condition['add_time'] = array('gt', $start_time);
                $result                = M('lottery_results')->where($condition)->limit(40)->order('c_no desc')->select();
                foreach ($result as $k => $v) {

                    $detail = explode(',', $v['lottery_result']);

                    $lm = explode(',', $v['lm']);
                    foreach ($detail as $key => $value) {
                        $key2                = $key + 1;
                        $detail['B' . $key2] = $value;
                        $detail['count']     = 10;
                        if ($value >= 5) {
                            $dx = '大';
                        } else {
                            $dx = '小';
                        }
                        if ($value % 2 == 1) {
                            $ds = '单';
                        } else {
                            $ds = '双';
                        }
                        $detail['DX' . $key2][0] = $dx;
                        $detail['DS' . $key2][0] = $ds;
                        $detail['ZDX'][0]        = $lm[2];
                        $detail['ZDS'][0]        = $lm[1];
                        $detail['LH'][0]         = $lm[3];
                    }

                    $data[$k]['detail']     = $detail;
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];

                }
                echo json_encode($data);exit(0);
                break;

            default:echo json_encode($data);exit(0);
                break;

        }

    }
    public function wx($sum)
    {

        if ($sum <= 695) {
            $dx = '金';
        } elseif ($sum <= 763 && $sum >= 696) {
            $dx = '木';
        } elseif ($sum <= 855 && $sum >= 764) {
            $dx = '水';
        } elseif ($sum <= 923 && $sum >= 856) {
            $dx = '火';
        } elseif ($sum <= 1410 && $sum >= 924) {
            $dx = '土';
        }
        return $dx;

    }
    public function zh_qh($num)
    {
        $a = 1;
        $b = 1;
        foreach ($num as $k => $v) {
            if ($v <= 40) {
                $a = $a + 1;
            } else {
                $b = $b + 1;
            }
        }
        if ($a > $b) {
            $dx = '前';
        } elseif ($a < $b) {
            $dx = '後';
        } else {
            $dx = '和';
        }

        return $dx;
    }
    //单双数比较
    public function zh_dsh($num)
    {
        $a = 1;
        $b = 1;
        foreach ($num as $k => $v) {
            if ($v % 2 == 0) {
                $a = $a + 1;
            } else {
                $b = $b + 1;
            }
        }
        if ($a > $b) {
            $dx = '双';
        } elseif ($a < $b) {
            $dx = '单';
        } else {
            $dx = '和';
        }
        return $dx;
    }

    public function color($v)
    {
        //1-5球红波绿波蓝波
        $bds   = array();
        $red   = array(1, 4, 7, 10, 13, 16, 19);
        $green = array(3, 6, 9, 12, 15, 18, 21);
        $blue  = array(2, 5, 8, 11, 14, 17, 20);

        if (in_array($v, $red)) {
            $bds = '红波';
        } elseif (in_array($v, $green)) {
            $bds = '绿波';
        } else {
            $bds = '蓝波';
        }

        return $bds;
    }
    public function fulsx($v)
    {
        //1-5球福禄寿喜

        if ($v >= 0 && $v <= 5) {
            $bds = '福';
        } elseif ($v >= 6 && $v <= 10) {
            $bds = '禄';
        } elseif ($v >= 11 && $v <= 15) {
            $bds = '寿';
        } elseif ($v >= 16 && $v <= 20) {
            $bds = '喜';
        } else {
            $bds = '和';
        }

        return $bds;
    }

    //1-8龙虎比较
    public function lh($num, $key)
    {

        foreach ($num as $k => $v) {
            $num[$k] = preg_replace('/^0+/', '', $v); //去除左边的0
        }
        $lh = array();
        if ($num[0] < $num[7]) {
            $lht = '虎';

        } else {
            $lht = '龙';
        }
        $lh[1] = $lht;
        if ($num[1] > $num[6]) {
            $lht = '龙';
        } else {
            $lht = '虎';
        }
        $lh[2] = $lht;
        if ($num[2] > $num[5]) {
            $lht = '龙';
        } else {
            $lht = '虎';
        }
        $lh[3] = $lht;
        if ($num[3] > $num[4]) {
            $lht = '龙';
        } else {
            $lht = '虎';
        }
        $lh[4] = $lht;
        $lh[5] = $lh[1];
        $lh[6] = $lh[2];
        $lh[7] = $lh[3];
        $lh[8] = $lh[4];

        return $lh[$key];
    }

}
